//wholehouse.js
import { ismsHouseBuypage } from '../../../../../config/config'
//获取应用实例
const app = getApp()

Page({
  data: {
    imgUrl:getApp().globalData.imgUrl,
    listData: [],
    page: 0,
    rows: 4,
    nomoreData: false,
    titleHeight: '',
    authorizationPopup: false
  },
  onLoad: function () {
    app.getLogin((re)=>{
      if(!re){
        this.setData({
          authorizationPopup: true
        })
      }
    })
    let that = this
    wx.getSystemInfo({
      success (res) {
        let statusBarHeight = res.statusBarHeight + 65
        console.log(statusBarHeight)
        that.setData({
          titleHeight: statusBarHeight + 'px'
        })
      }
    })
    that.getListData()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.nomoreData) {
      this.setData({
        page: this.data.page + 1
      })
      this.getListData()
    }
  },
  // 获取列表数据
  getListData() {
    let that = this
    let params = {
      "page": that.data.page,
      "rows": that.data.rows
    }
    app.reqFun.requestJson('POST',ismsHouseBuypage,params,(res)=>{
      if(res.data.success==1){
        let records = res.data.data.records
        if (records.length < that.data.rows ||　records.length == that.data.rows) {
          that.setData({
            nomoreData: true
          })
        }
        that.setData({
          listData: that.data.listData.concat(records)
        })
      }
    }) 
  },
  // 跳转详情
  goDetails(e) {
    let activityId = e.currentTarget.dataset.item.activityId
    let id = e.currentTarget.dataset.item.id
    let option = {
      activityId: activityId,
      id: id
    }
    wx.navigateTo({
      url: '/packagBuy/pages/marketing/wholehouse/details/details?option=' + JSON.stringify(option),
    })
  },
  goreBack(e){
    wx.navigateBack({
      delta: 1,
    })
  }
})
